package com.justgame.project.service.just.query;

import java.util.List;
import java.util.ArrayList;
import java.util.Optional;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.justgame.project.cloud.common.query.Column;
import com.justgame.project.cloud.common.query.BaseSelectBuilder;
import com.justgame.project.cloud.common.query.AbstractQueryWrapper;
import com.justgame.project.cloud.common.query.Query;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.justgame.project.service.just.entity.JustGameInfo;
import com.justgame.project.service.system.query.SysUserInfoQuery;
import com.justgame.project.service.just.entity.JustGameCompany;
import com.justgame.project.service.system.entity.SysUserInfo;
import com.justgame.project.service.just.query.JustGameCompanyQuery;
import com.justgame.project.service.just.wrapper.JustGameInfoWrapper;

public class JustGameInfoQuery extends AbstractQueryWrapper<JustGameInfo, MPJLambdaWrapper<JustGameInfo>, JustGameInfoWrapper> {

    private JustGameInfoQuery() {
        super(new MPJLambdaWrapper<>(JustGameInfo.class,"just_game_info"));
    }

    public static JustGameInfoQuery builder(){
        return new JustGameInfoQuery();
    }

    public static class Select{

        private final List<Query> queries;

        protected Select(){
            queries = new ArrayList<>();
        }

        protected Select(List<Query> queries) {
            this.queries = queries;
        }

        public Query[] getQueriesArray() {
            return queries.toArray(new Query[0]);
        }

        public static SelectBuilder builder(){
            return new SelectBuilder();
        }

        public Query[] build(){
            return queries.toArray(new Query[0]);
        }

        public static class SelectBuilder extends BaseSelectBuilder {
            public SelectBuilder JustGameInfo(){
                return JustGameInfo(Column.all());
            }

            public SelectBuilder JustGameInfo(Column column){
                return add(Query.builder(JustGameInfo.class)
                            .selectColumns(column)
                            .build());
            }

            public SelectBuilder createUser(){
                return createUser(Column.all());
            }

            public SelectBuilder createUser(Column column){
                return createUser(column, null);
            }

            public SelectBuilder createUser(Column column,SysUserInfoQuery.Select selectQuery){
                return createUser("createUserWrapper", column, null);
            }

            public SelectBuilder createUser(String mappingName,Column column,SysUserInfoQuery.Select selectQuery){
                return add(Query.builder(SysUserInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .rightOn((SFunction<JustGameInfo,?>)JustGameInfo::getCreateUser)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder updateUser(){
                return updateUser(Column.all());
            }

            public SelectBuilder updateUser(Column column){
                return updateUser(column, null);
            }

            public SelectBuilder updateUser(Column column,SysUserInfoQuery.Select selectQuery){
                return updateUser("updateUserWrapper", column, null);
            }

            public SelectBuilder updateUser(String mappingName,Column column,SysUserInfoQuery.Select selectQuery){
                return add(Query.builder(SysUserInfo.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<SysUserInfo,?>)SysUserInfo::getId)
                            .rightOn((SFunction<JustGameInfo,?>)JustGameInfo::getUpdateUser)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(SysUserInfoQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public SelectBuilder justGameCompany(){
                return justGameCompany(Column.all());
            }

            public SelectBuilder justGameCompany(Column column){
                return justGameCompany(column, null);
            }

            public SelectBuilder justGameCompany(Column column,JustGameCompanyQuery.Select selectQuery){
                return justGameCompany("justGameCompanyWrapper", column, null);
            }

            public SelectBuilder justGameCompany(String mappingName,Column column,JustGameCompanyQuery.Select selectQuery){
                return add(Query.builder(JustGameCompany.class)
                            .mapping(mappingName)
                            .leftOn((SFunction<JustGameCompany,?>)JustGameCompany::getId)
                            .rightOn((SFunction<JustGameInfo,?>)JustGameInfo::getCompanyId)
                            .selectColumns(column)
                            .join(Optional.ofNullable(selectQuery).map(JustGameCompanyQuery.Select::getQueriesArray).orElse(null))
                            .build());
            }

            public Select build(){
                return new Select(getQueries());
            }
        }

    }
}